package com.googlecode.dgwt.client.dojo.data.format;

public class CharFormatter extends BaseFormatter<Character> {

    private static CharFormatter formatter;
    
    protected CharFormatter() {
    }
    
    @Override
    public Character unformatValue(String value) {
        if (value == null) {
            return null;
        }

        if (value.isEmpty()) {
            return null;
        }
        
        if (value.length() > 1) {
            value = value.trim();
        }

        return Character.valueOf(value.isEmpty() ? ' ' : value.charAt(0));
    }

    public static CharFormatter get() {
        if (formatter == null) {
            formatter = new CharFormatter();
        }
        return formatter;
    }

}
